package com.zyh.zapiinterface.controller;

import com.zyh.zapiclientsdk.model.User;
import com.zyh.zapiclientsdk.utils.SignUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 查询名字接口
 */
@RestController
@RequestMapping("/name")
public class NameController {
    @GetMapping("/")
    public String getNameByGet(String name){
        return "GET你的名字是"+name;
    }

    @PostMapping("/")
    public String getNameByPost(@RequestParam String name){
        return "POST你的名字是"+name;
    }
    @PostMapping ("/user")
    public String getUsernameByPost(@RequestBody User user, HttpServletRequest request){
//        String accessKey = request.getHeader("accessKey");
//        String nonce = request.getHeader("nonce");
//        String timestamp = request.getHeader("timestamp");
//        String sign = request.getHeader("sign");
//        String body = request.getHeader("body");
//        if(!accessKey.equals("zyh")){
//            throw new RuntimeException("无权限");
//        }
//        if(Long.parseLong(nonce) > 10000){
//            throw new RuntimeException("无权限1");
//        }
//        //todo时间戳校验
//        //...
//
//        String serverSign = SignUtils.genSign(body, "abcdefg");
//        if(!sign.equals(serverSign)){
//            throw new RuntimeException("无权限2");
//        }
        return "POST用户名字是"+user.getUsername();
    }
}
